<?php
namespace Crm\Controller;

use Zend\View\Model\ViewModel;
/**
 * 监管平台
 */
class SupervisionController extends AbstractController
{
	public function orgAction(){
	    return new ViewModel();
	}

	public function ajaxOrgListAction(){
	    $request = $this->request->getPost()->toArray();
	    (int) $page = isset($request['page']) ? $request['page'] : 1;
	    
	    $query = array(
	        'page' => $page
	    );
	    
	    $paginator = $this->getOrganizationTable()->findAllSupervision($query);
	    
	    $result = array(
	        'paginator' => $paginator
	    );
	    $viewModel = new ViewModel();
	    $viewModel->setVariables($result)->setTerminal(true);
	    
	    return $viewModel;
	}
	
	       
	public function materialAction(){
	    return new ViewModel();
	
	}
	
	public function ajaxMaterialListAction(){
	    $request = $this->request->getPost()->toArray();
	    (int) $page = isset($request['page']) ? $request['page'] : 1;
	     
	    $query = array(
	        'page' => $page
	    );
	    
	    $paginator = $this->getMaterialTable()->findAllSupervision($query);
	    $result = array(
	        'paginator' => $paginator
	    );
	    $viewModel = new ViewModel();
	    $viewModel->setVariables($result)->setTerminal(true);
	     
	    return $viewModel;
	}
	
	public function orgGoodsAction(){
	
	    return new ViewModel();
	}
	
	public function ajaxOrgGoodsListAction(){
	    $request = $this->request->getPost()->toArray();
	    (int) $page = isset($request['page']) ? $request['page'] : 1;
	
	    $query = array(
	        'page' => $page
	    );

	    $paginator = $this->getProductTable()->findAllSupervision($query);
	    $result = array(
	        'paginator' => $paginator
	    );
	    $viewModel = new ViewModel();
	    $viewModel->setVariables($result)->setTerminal(true);
	
	    return $viewModel;
	}

	/**
	 * AJAX请求 商户商品溯源数据
	 */
	public function ajaxOrgGoodsMaterialListAction()
	{
	    $request = $this->getRequest()->getQuery();
	    (int) $id = $request['product_id'];
	    $response_res = $this->getMaterialTable()->findAllByProductId($id);

	    $html_content = '';
	    //<td  colspan="2"><a href="javascript:editAddress( '.$v['id']. ');">修改</a></td>
	    if($response_res){
	        $html_content .= '<td calss="details"  colspan="11">';
	        $html_content .= '<table id="address-list-show"  class="table table-hover">';
	        $html_content .= '<tbody>';
	        foreach($response_res as $v){
	            $html_content .= ' <tr>';
	            $html_content .= '<td style="text-align:left">' .$v['material_name']. ' </td>';
	            $html_content .= '</tr>';
	        }
	        $html_content .= ' </tbody>';
	        $html_content .= '</table>';
	        $html_content .= ' </td>';
	
	    }
	    die($html_content);
	
	}
	
	
	public function orderAction(){
	
	    return new ViewModel();
	}
	
	
	public function ajaxOrderListAction(){
	    $request = $this->request->getPost()->toArray();
	    (int) $page = isset($request['page']) ? $request['page'] : 1;
	
	    $query = array(
	        'page' => $page
	    );

	    $paginator = $this->getOrderTable()->findAllSupervision($query);
	    $result = array(
	        'paginator' => $paginator
	    );
	    $viewModel = new ViewModel();
	    $viewModel->setVariables($result)->setTerminal(true);
	
	    return $viewModel;
	}
	
	/**
	 * AJAX请求 订单商品数据
	 */
	public function ajaxOrderGoodsListAction()
	{
	    $request = $this->getRequest()->getQuery();
	    (int) $id = $request['order_id'];
	    $response_res = $this->getOrderitemTable()->findAllByOrderId($id);

	    $html_content = '';
	    //<td  colspan="2"><a href="javascript:editAddress( '.$v['id']. ');">修改</a></td>
	    if($response_res){
	        $html_content .= '<td calss="details"  colspan="11">';
	        $html_content .= '<table id="order-goods-list-show" class="table table-hover">';
	        $html_content .= '<tbody>';
	        foreach($response_res as $v){
	            $html_content .= ' <tr>';
	            $html_content .= '<td style="text-align:left">'.'商品名称：' .$v['oi_name'].'</td>';
	            $html_content .= '<td style="text-align:left">用餐时间：' .$v['oi_meal_send_time'].' </td>';
	            $html_content .= '</tr>';
	        }
	        $html_content .= ' </tbody>';
	        $html_content .= '</table>';
	        $html_content .= ' </td>';
	
	    }
	    die($html_content);
	
	}
	
	public function ajaxCommonOrderListAction(){
	    $request = $this->request->getPost()->toArray();
	    (int) $page = isset($request['page']) ? $request['page'] : 1;
	    (int) $catalog_id = isset($request['catalog_id']) ? $request['catalog_id'] : 0;
	    
	    $query = array(
	        'page' => $page,
	        'catalog_id' => $catalog_id
	    );
	
	    $paginator = $this->getOrderTable()->findAllSupervision($query);
	    $result = array(
	        'paginator' => $paginator
	    );
	    $viewModel = new ViewModel();
	    $viewModel->setVariables($result)->setTerminal(true);
	
	    return $viewModel;
	}
	
	/**
	 * AJAX请求 订单商品数据
	 */
	public function ajaxCommonOrderGoodsListAction()
	{
	    $request = $this->getRequest()->getQuery();
	    (int) $id = $request['order_id'];
	    $response_res = $this->getOrderitemTable()->findAllByOrderId($id);
	
	    $html_content = '';
	    //<td  colspan="2"><a href="javascript:editAddress( '.$v['id']. ');">修改</a></td>
	    if($response_res){
	        $html_content .= '<td calss="details"  colspan="11">';
	        $html_content .= '<table id="address-list-show" class="table table-hover">';
	        $html_content .= '<tbody>';
	        foreach($response_res as $v){
	            $html_content .= ' <tr>';
	            $html_content .= '<td style="text-align:left">'.'商品名称：' .$v['oi_name']. ' </td>';
	            $html_content .= '<td style="text-align:left">用餐时间：' .$v['oi_meal_send_time'].' </td>';
	             
	            $html_content .= '</tr>';
	        }
	        $html_content .= ' </tbody>';
	        $html_content .= '</table>';
	        $html_content .= ' </td>';
	
	    }
	    die($html_content);
	
	}
	
	public function schoolAction(){
	
	    return new ViewModel();
	}
	
	public function enterpriseAction(){
	
	    return new ViewModel();
	}
	
	public function hospitalAction(){
	
	    return new ViewModel();
	}
	
	public function administrativeAction(){
	
	    return new ViewModel();
	}
	
}